Make a cooler JList interface
Content:1. The working principle of the drawing device.2. Replace the appearance of JList and JComboBox with a custom drawing.3. Let the new look respond to mouse events.
With the swing system's MVC design concept, it's easy to replace different skins for components. This article mainly takes jlist and JComboBox as an example to expl
Show
Click here to download the source file
IntroductionIn the graphical user interface (GUI), Java has been unable to compete with C + +, PB, Delphi and so on, the use of the early JAVA/AWT package developed by the interface is really people dare not to compliment. With the maturing of jfc/swing, it is no longer an "impossible task" to develop a GUI comparable to C + +. In addition to its rich interface components, the following excellent features make swing even more powerful. Swing is i
I have not mastered the right-click menu in some components for a long time, and I have always felt quite difficult (it really seems that I am stupid, but I am in a daze spirit, and I succeeded today, but it will be nice to understand it later. So let's take a look at it and share it with you. 1: define variables. Jlist; jpopupmenu; jmenuitem; jsonjradiobuttonmenuitem; jcheckboxmenuitem; jseparator; 2: Initialize member variables. Saving, no writing.
Use of JList
JList compared to Jcheckbox, you can select a maximum of one item, and JList can be selected as a whole column .
The third constructor cannot change the number of items
--Construct a simple listImportJava.awt.Container;Importjava.awt.GridLayout;ImportJava.awt.event.WindowAdapter;Importjava.awt.event.WindowEvent;ImportJava.util.Vect
; - } - Private intMinintAintBintc) { in returnMath.min (Math.min (A, B), c); -}Having said so much, I'll talk about the subject, JList ...Question 1:jlist's ListenersFirst ate a listselectionlistener of the loss ah, the result because of this GUI in the other listeners conflict, then abandoned, instead of MouseListener and KeyListener (only up and down), This was solved ... Tear eyes ...Question 2: Dynamic jlistBecause
A list box can also be used to create a list box when information is presented to the user's list of multiple options, using JList.Package Com.beyole.util;import Java.awt.container;import Java.awt.gridlayout;import java.awt.event.WindowAdapter; Import Java.awt.event.windowevent;import Java.util.vector;import Javax.swing.borderfactory;import Javax.swing.jframe;import Javax.swing.jlist;import javax.swing.listselectionmodel;class MyList {private JFrame frame = new JFrame ("Beyole");p rivate Contain
Scenario: You can enter a character in a list to dynamically filter the display of items in the list. Of course, all the items displayed dynamically contain characters entered by the user! Here, the implementation of the function is very simple, there is no moreComplex logic. It only provides some examples for learners. You can perform the extensions you need.[Relationship diagram ]:
In Swing, to build your own components, the simplest thing is to inherit the existing components, and then perfor
Swing custom jlist
First, explain
Each entry in the middle is a cell. Here we use jpanel to display the cell, so we can add buttons, labels, and checkbox on the panel... Do what you want.
Click remove to delete the current row.
Complete engineering http://download.csdn.net/detail/jasper_success/4488517
Key code
/*** Custom jlist. Each cell is a component, which can be defined at will, for example, A jpane
1. Define JList
2. Add mouse Monitor on the JList object (MouseListener)
3. After the Click event is triggered, determine its position in the jlist, and then determine the number of hits, depending on the number of times to select the processing function.
String data[] = {"Red", "Blue", "green"};
JList
jtable scrolling. The scrollrecttovisible function forwards the call to its parent container for processing. The parent container chooses to continue forwarding or process the request.
The scrollrecttovisible function receives only one rectangle parameter, indicating which region you want to be visible. For jtable, obtain the required parameters in the following way:
Int x = jtable1.getbounds (). X;
Int y = jtable1.getrowheight () * rowindex;
Int width = jtable1.getbounds (). width;
Int Height
OK, I admit that the word "dynamic" is used a bit. Let's take a look at the effect and explain it first. There is nothing dynamic in the picture. In fact, the effect is that when the item is selected in this way, the selected blue background changes
Java graphical user interface list box, java graphical list box
The list box is generated by the Swing component JList, which occupies a fixed number of rows on the screen. To obtain the selected element in the list box, you only need to call getSelectedValuesList () to generate a string array with the selected element name. The JList component allows multiple selections. If you press Ctrl, you can select a
The list box is generated by the swing component jlist, which always occupies a fixed number of rows on the screen. To get the selected element in the list box, simply call Getselectedvalueslist (), which produces an array of strings with the selected element name. JList components allow multiple selections; If you hold down the CTRL key, you can select all the clicked elements, and if you select an element
model, because it is also a visual state, the selected item will be highlighted (high light). As with other gui-state model, we usually do not need to directly manipulate selection model.
The status of the Selection model identification is:
Single_selection
Single_interval_selection
Multiple_interval_selection
Let's analyze other needs to judge the user to select several controls
JList, like JTable, is ListSelectionModel.
JTree, JTree nee
java.util.properties;
.....
Properties sys = system.getproperties ();
Sys.put ("Proxyset", "true");
Sys.put ("ProxyHost", "myHTTP.proxyserver.com");
Sys.put ("ProxyPort", "80");
System.setproperties (SYS);
u = new URL (website);
Connect = (httpurlconnection) u.openconnection ();
.....
Q: The Swing component JList list data has been modified, how to notify the JList change display?
For:
The
Problem
Sys.put ("ProxyHost", "myHTTP.proxyserver.com");
Sys.put ("ProxyPort", "80");
System.setproperties (SYS);
u = new URL (website);
Connect = (httpurlconnection) u.openconnection ();
.....
Q: The Swing component JList list data has been modified, how to notify the JList change display?
For:
The JList component has a separate display mode Listmodel to
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.